<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="任务号" prop="taskNo">
        <el-input v-model="queryParams.taskNo" placeholder="请输入任务号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="项目名称" prop="projectName">
        <el-input v-model="queryParams.projectName" placeholder="请输入项目名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="组别号" prop="version">
        <el-input v-model="queryParams.version" placeholder="请输入组别号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="图号" prop="drawingNo">
        <el-input v-model="queryParams.drawingNo" placeholder="请输入图号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="机型" prop="productModel">
        <el-input v-model="queryParams.productModel" placeholder="请输入机型" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['product:taskInfo:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['product:taskInfo:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="info" icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['product:taskInfo:export']">导出计算文件</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table stripe border v-loading="loading" :data="taskInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" width="55" type="index" />
      <el-table-column label="任务号" align="center" prop="taskNo" min-width="150" show-overflow-tooltip />
      <el-table-column label="项目名称" align="center" prop="projectName" min-width="150" show-overflow-tooltip />
      <el-table-column label="用户" align="center" prop="userName" min-width="150" show-overflow-tooltip />
      <el-table-column label="类别" align="center" prop="category" min-width="150" show-overflow-tooltip />
      <el-table-column label="合同号" align="center" prop="contractNumber" min-width="150" show-overflow-tooltip />
      <!-- <el-table-column
        label="组别号"
        align="center"
        prop="version"
        min-width="150"
        show-overflow-tooltip
      />
      <el-table-column
        label="图号"
        align="center"
        prop="drawingNo"
        min-width="150"
        show-overflow-tooltip
      /> -->
      <el-table-column label="工质" align="center" prop="productMedium" min-width="150" show-overflow-tooltip />
      <el-table-column label="配置" align="center" prop="unitLayout" min-width="150" show-overflow-tooltip />
      <el-table-column label="轴流连接端" align="center" prop="shaftConnection" min-width="150" show-overflow-tooltip />
      <el-table-column label="静叶执行机构" align="center" prop="bladeExecution" min-width="150" show-overflow-tooltip />
      <el-table-column label="驱动机功率" align="center" prop="driverPower" min-width="150" show-overflow-tooltip />
      <el-table-column label="计算文件" align="center" prop="calcFile" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <div @click="openFile(scope.row)" style="color: #0275cd; width: 100px; cursor: pointer">{{ scope.row.calcFile }}</div>
        </template>
      </el-table-column>
      <el-table-column label="机型" align="center" prop="productModel" min-width="150" show-overflow-tooltip />
      <el-table-column label="产品级数" align="center" prop="productModelCode" min-width="150" show-overflow-tooltip />

      <el-table-column label="转速r/min" align="center" prop="speedRpm" min-width="150" show-overflow-tooltip />
      <el-table-column label="启动角度" align="center" prop="startupAngle" min-width="150" show-overflow-tooltip />
      <el-table-column label="安全运行角" align="center" prop="safeOperatingAngle" min-width="150" show-overflow-tooltip />
      <el-table-column label="长期最小运行角" align="center" prop="longTermMinOperatingAngle" min-width="150"
        show-overflow-tooltip />
      <el-table-column label="最大静叶角度" align="center" prop="maxStaticBladeAngle" min-width="150" show-overflow-tooltip />
      <el-table-column label="启动内功率" align="center" prop="startupInternalPower" min-width="150" show-overflow-tooltip />
      <el-table-column label="测频要求" align="center" prop="frequencyRequire" min-width="150" show-overflow-tooltip />
      <el-table-column label="曲线名称" align="center" prop="curveName" min-width="150" show-overflow-tooltip />
      <el-table-column label="工况调节方式" align="center" prop="adjustMode" min-width="150" show-overflow-tooltip />
      <el-table-column label="大气参数" align="center" prop="adjustMode" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <div style="
              border-bottom: 1px solid #0275cd;
              color: #0275cd;
              padding-bottom: 2px;
              width: 50px;
              margin: auto;
            " @click="openTables(scope.row, '大气参数')">
            大气参数
          </div>
        </template>
      </el-table-column>

      <el-table-column label="设计参数" align="center" prop="adjustMode" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <div style="
              border-bottom: 1px solid #0275cd;
              color: #0275cd;
              padding-bottom: 2px;
              width: 50px;
              margin: auto;
            " @click="openTables(scope.row, '设计参数')">
            设计参数
          </div>
        </template>
      </el-table-column>
      <el-table-column label="工况点性能参数" align="center" prop="adjustMode" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <div style="
              border-bottom: 1px solid #0275cd;
              color: #0275cd;
              padding-bottom: 2px;
              width: 50px;
              margin: auto;
            " @click="openTables(scope.row, '工况点性能参数')">
            工况点
          </div>
        </template>
      </el-table-column>

      <el-table-column label="轴向推力" align="center" prop="adjustMode" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <div style="
              border-bottom: 1px solid #0275cd;
              color: #0275cd;
              padding-bottom: 2px;
              width: 50px;
              margin: auto;
            " @click="openTables(scope.row, '轴向推力')">
            轴向推力
          </div>
        </template>
      </el-table-column>

      <el-table-column label="阻塞线" align="center" prop="adjustMode" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <div style="
              border-bottom: 1px solid #0275cd;
              color: #0275cd;
              padding-bottom: 2px;
              width: 50px;
              margin: auto;
            " @click="openTables(scope.row, '阻塞线')">
            阻塞线
          </div>
        </template>
      </el-table-column>
      <!-- <el-table-column
        label="核验状态"
        align="center"
        prop="adjustMode"
        min-width="150"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <div
            style="
              border-bottom: 1px solid #0275cd;
              color: #0275cd;
              padding-bottom: 2px;
              width: 50px;
              margin: auto;
            "
            @click="designSubmit(scope.row)"
          >
            设计提交
          </div>
        </template>
      </el-table-column> -->
      <el-table-column label="审核状态" align="center" prop="approverFlag" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <div @click="designSubmit(scope.row)">
            <el-tag type="info" v-if="scope.row.approverFlag == 0">未提交</el-tag>
            <el-tag v-if="scope.row.approverFlag == 1">待校验</el-tag>
            <el-tag type="success" v-if="scope.row.approverFlag == 2">待核验</el-tag>
            <el-tag type="warning" v-if="scope.row.approverFlag == 3">已通过</el-tag>
            <el-tag type="danger" v-if="scope.row.approverFlag == 4">未通过</el-tag>
          </div>
        </template>
      </el-table-column>
      <!-- <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="审批状态" align="center" prop="approverFlag" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200">
        <!--    -->
        <template slot-scope="scope">
          <el-button v-if="scope.row.approverFlag == 4 || scope.row.approverFlag == 0" size="mini" type="text"
            @click="handleUpdate(scope.row)" v-hasPermi="['product:taskInfo:edit']">修改</el-button>
          <el-button size="mini" type="text" v-if="scope.row.approverFlag == 4 || scope.row.approverFlag == 0"
            @click="handleDelete(scope.row)" v-hasPermi="['product:taskInfo:remove']">删除</el-button>
          <el-button size="mini" type="text" v-if="scope.row.approverFlag == 4 || scope.row.approverFlag == 0"
            @click="handleSubmit(scope.row)" v-hasPermi="['product:taskInfo:submit']">提交</el-button>
          <el-button size="mini" type="text" @click="handleAnnex(scope.row)"
            v-hasPermi="['product:taskInfo:file']">附件</el-button>
          <el-button size="mini" type="text" @click="handleDetail(scope.row)"
            v-hasPermi="['product:taskInfo:detail']">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改任务信息对话框 -->
    <el-dialog v-dialogDrag :close-on-click-modal="false" :title="title" :visible.sync="open" width="910px"
      append-to-body>
      <div style="display: flex; justify-content: end; margin-bottom: 10px">
        <el-button type="primary" size="mini" @click="handledownLoad">下载模板</el-button>
        <el-button type="primary" size="mini" @click="handleImport"
          v-hasPermi="['product:taskInfo:import']">导入</el-button>
      </div>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px" :inline="true" class="addData">
        <el-form-item label="任务号" prop="taskNo">
          <el-input v-model="form.taskNo" placeholder="请输入任务号" />
        </el-form-item>
        <el-form-item label="项目名称" prop="projectName">
          <el-input v-model="form.projectName" placeholder="请输入项目名称" />
        </el-form-item>
        <el-form-item label="用户" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入用户" />
        </el-form-item>
        <el-form-item label="类别" prop="category">
          <el-input v-model="form.category" placeholder="请输入类别" />
        </el-form-item>
        <el-form-item label="合同号" prop="contractNumber">
          <el-input v-model="form.contractNumber" placeholder="请输入合同号" />
        </el-form-item>
        <el-form-item label="工质" prop="productMedium">
          <el-input v-model="form.productMedium" placeholder="请输入工质" />
        </el-form-item>
        <el-form-item label="配置" prop="unitLayout">
          <el-input v-model="form.unitLayout" placeholder="请输入配置" />
        </el-form-item>
        <el-form-item label="轴流连接端" prop="shaftConnection">
          <el-select v-model="form.shaftConnection" placeholder="请选择轴流连接端" clearable>
            <el-option v-for="dict in dict.type.connect" :key="dict.value" :label="dict.label" :value="dict.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="静叶执行机构" prop="bladeExecution">
          <el-select v-model="form.bladeExecution" placeholder="请选择静叶执行机构" clearable>
            <el-option v-for="dict in dict.type.execute" :key="dict.value" :label="dict.label" :value="dict.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="驱动机功率" prop="driverPower">
          <el-input v-model="form.driverPower" placeholder="请输入驱动机功率" />
        </el-form-item>
        <el-form-item label="计算文件" prop="calcFile">
          <el-input v-model="form.calcFile" placeholder="请输入计算文件名" />
        </el-form-item>
        <el-form-item label="机型" prop="productModel">
          <el-input v-model="form.productModel" placeholder="请输入机型" />
        </el-form-item>
        <el-form-item label="产品级数" prop="productModelCode">
          <el-input v-model="form.productModelCode" placeholder="请输入产品级数" />
        </el-form-item>
        <el-form-item label="转速r/min" prop="speedRpm">
          <el-input v-model="form.speedRpm" placeholder="请输入转速r/min" />
        </el-form-item>
        <el-form-item label="启动角度" prop="startupAngle">
          <el-input v-model="form.startupAngle" placeholder="请输入启动角度" />
        </el-form-item>
        <el-form-item label="启动内功率" prop="startupInternalPower">
          <el-input v-model="form.startupInternalPower" placeholder="请输入启动内功率" />
        </el-form-item>
        <el-form-item label="安全运行角" prop="safeOperatingAngle">
          <el-input v-model="form.safeOperatingAngle" placeholder="请输入安全运行角" />
        </el-form-item>
        <el-form-item label="长期最小运行角" prop="longTermMinOperatingAngle">
          <el-input v-model="form.longTermMinOperatingAngle" placeholder="请输入长期最小运行角" />
        </el-form-item>
        <el-form-item label="最大静叶角度" prop="maxStaticBladeAngle">
          <el-input v-model="form.maxStaticBladeAngle" placeholder="请输入最大静叶角度" />
        </el-form-item>
        <el-form-item label="曲线名称" prop="curveName">
          <el-input v-model="form.curveName" placeholder="请输入曲线名称" />
        </el-form-item>
        <el-form-item label="工况调节方式" prop="adjustMode">
          <el-select v-model="form.adjustMode" placeholder="请选择工况调节方式" clearable>
            <el-option v-for="dict in dict.type.accommodation" :key="dict.value" :label="dict.label"
              :value="dict.value" />
          </el-select>
        </el-form-item>
        <el-row>
          <el-col :span="24">
            <el-form-item label="测频要求" prop="frequencyRequire">
              <el-input v-model="form.frequencyRequire" type="textarea" style="width: 690px" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" type="textarea" style="width: 690px" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 大气压力 -->
        <!-- <atmosphere
          @getTtaskEnvList="getTtaskEnvList"
          :formData="form.ttaskEnvList"
        ></atmosphere> -->
        <el-divider content-position="center">大气参数</el-divider>
        <div class="weather-table">
          <!-- 如需整页容器，可自己包一层 el-card -->
          <el-table :data="tableData" :span-method="spanMethod" border style="width: 100%" size="mini">
            <!-- 左侧固定列：汽参数 -->
            <el-table-column prop="param" label="" width="90" align="center" />
            <el-table-column prop="titles" label="" align="center" />

            <el-table-column prop="unit" label="单位" width="90" align="center" />
            <el-table-column label="夏季平均" align="center" width="200">
              <template slot-scope="{ row }">
                <!-- <el-input
                  v-model="row.summer"
                  size="mini"
                  style="width: 130px !important"
                /> -->

                <el-input-number :disabled="row.disabled" style="width: 100px !important" :controls="false"
                  v-model="row.summer" :min="0" :max="10000000000"></el-input-number>
              </template>
            </el-table-column>

            <el-table-column label="冬季平均" align="center" width="200">
              <template slot-scope="{ row }">
                <!-- <el-input
                  v-model="row.winter"
                  size="mini"
                  style="width: 130px !important"
                /> -->

                <el-input-number style="width: 100px !important" :controls="false" v-model="row.winter" :min="0"
                  :disabled="row.disabled" :max="10000000000"></el-input-number>
              </template>
            </el-table-column>

            <el-table-column label="年平均" align="center" width="200">
              <template slot-scope="{ row }">
                <!-- <el-input
                  v-model="row.annual"
                  size="mini"
                  style="width: 130px !important"
                /> -->
                <el-input-number style="width: 100px !important" :controls="false" v-model="row.annual" :min="0"
                  :disabled="row.disabled" :max="10000000000"></el-input-number>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <!-- 设计参数 -->
        <ttaskConditionParamList :formData="form.ttaskConditionParamList"
          @getTtaskConditionParamList="getTtaskConditionParamList"></ttaskConditionParamList>
        <!-- 工况点性能参数 -->
        <ttaskPerformancePointList :formData="form.ttaskPerformancePointList"
          @getTtaskPerformancePointList="getTtaskPerformancePointList"></ttaskPerformancePointList>
        <!-- 轴向推力 -->
        <ttaskThrustList :formData="form.ttaskThrustList" @getTtaskThrustList="getTtaskThrustList"></ttaskThrustList>
        <!--  阻塞线信息-->
        <ttaskBlockLineList :formData="form.ttaskBlockLineList" @getTtaskBlockLineList="getTtaskBlockLineList">
        </ttaskBlockLineList>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <moreTables @closeAct="closeAct" :rowId="rowId" :ActTitle="ActTitle" :openAct="openAct"></moreTables>

    <ApprovalRecords @closeRecords="closeRecords" :rowId="rowId" :openRecords="openRecords"></ApprovalRecords>

    <el-dialog title="导入文件" v-dialogDrag :visible.sync="openImport" width="800px" append-to-body :show-close="false">
      <file-upload v-model="importFile" />

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="cancelFormImport">取 消</el-button>
        <el-button type="primary" @click="submitFormImport">确 定</el-button>
      </div>
    </el-dialog>

    <ApprovalDetails @close="handleDetailClose" ref="approvalDetails" :detailsId="detailsId" :openView="openView">
    </ApprovalDetails>

    <el-dialog title="在线预览" :visible.sync="lineOpen" width="900px" append-to-body v-dialogDrag>
      <div style="display: flex;justify-content: flex-end;margin: 10px;">
        <el-button @click="handleExports(fileUrl)" size="mini" type="primary">下载</el-button>
      </div>
      <PdfViewer v-if="fileType === 'pdf' && fileUrl" :fileUrl="fileUrl" @loading="handleLoading"
        @error="handleError" />

      <DocxViewer v-else-if="fileType === 'docx' && fileUrl" :fileUrl="fileUrl" @loading="handleLoading"
        @error="handleError" />

      <ExcelViewer v-else-if="fileType === 'xlsx' && fileUrl" :fileUrl="fileUrl" @loading="handleLoading"
        @error="handleError" />


      <el-image v-else-if="fileType === 'png' || fileType === 'jpg' || fileType === 'jpeg'"
        style=" width: 100px; height: 100px" :src="fileUrl" :preview-src-list="[fileUrl]">
      </el-image>
    </el-dialog>
  </div>
</template>

<script>
import {
  listTaskInfo,
  getTaskInfo,
  delTaskInfo,
  addTaskInfo,
  updateTaskInfo,
  taskSubmit,
  taskInfoImport,
} from "@/api/fileManage/entering";
import PdfViewer from "../../components/PdfViewer.vue";
import DocxViewer from "../../components/DocxViewer.vue";
import ExcelViewer from "../../components/ExcelViewer.vue";
import moreTables from "./moreTables";
// 大气压力
import atmosphere from "./atmosphere";
// 轴向推力
import ttaskThrustList from "./ttaskThrustList";
//阻塞线信息
import ttaskBlockLineList from "./ttaskBlockLineList";
// 工况点性能参数
import ttaskPerformancePointList from "./ttaskPerformancePointList";
// 设计参数
import ttaskConditionParamList from "./ttaskConditionParamList";
import ApprovalRecords from "../ApprovalRecords.vue";
import ApprovalDetails from "../details.vue";
import {
  getInfoByName
} from "@/api/product/productInfo";
export default {
  components: {
    ApprovalDetails,
    atmosphere,
    ttaskThrustList,
    ttaskBlockLineList,
    ttaskPerformancePointList,
    ttaskConditionParamList,
    moreTables,
    ApprovalRecords,
    PdfViewer,
    DocxViewer,
    ExcelViewer,
  },
  name: "TaskInfo",
  dicts: ["connect", "execute", "accommodation"],
  data() {
    return {
      lineOpen: false,
      fileUrl: "",
      fileType: "docx",
      openView: false,
      ttaskEnvList: [],
      detailsId: "",
      openDetail: false,
      openImport: false,
      importFile: "",
      openRecords: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 任务信息表格数据
      taskInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        taskNo: null,
        projectId: null,
        projectName: null,
        userName: null,
        version: null,
        drawingNo: null,
        productMedium: null,
        unitLayout: null,
        shaftConnection: null,
        bladeExecution: null,
        driverPower: null,
        calcFile: null,
        productModel: null,
        speedRpm: null,
        startupAngle: null,
        safeOperatingAngle: null,
        longTermMinOperatingAngle: null,
        maxStaticBladeAngle: null,
        startupInternalPower: null,
        frequencyRequire: null,
        curveName: null,
        adjustMode: null,
        approverFlag: null,
        productModelCode: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      rowId: "",
      openAct: false,
      ActTitle: "",

      tableData: [
        {
          titles: "大气压力",
          param: "大气参数",
          unit: "kPa(a)",
          atmosphericPressure: "", // 夏季平均
          winter: "", // 冬季平均
          annual: "", // 年平均
          summer: "",
        },
        {
          titles: "大气温度",
          param: "大气参数",
          unit: "℃",
          atmosphericPressure: "",
          winter: "",
          annual: "",
          summer: "",
        },
        {
          titles: "大气温度",
          param: "大气参数",
          unit: "K",
          atmosphericPressure: "",
          winter: "",
          annual: "",
          summer: "",
          disabled: true,
        },
        {
          titles: "绝对湿度",
          param: "大气参数",
          unit: "mb",
          atmosphericPressure: "",
          winter: "",
          annual: "",
          summer: "",
        },
        {
          titles: "相对湿度",
          param: "大气参数",
          unit: "%",
          atmosphericPressure: "",
          winter: "",
          annual: "",
          summer: "",
        },
      ],
    };
  },
  created() {
    this.getList();
  },
  watch: {
    tableData: {
      handler(newVal) {
        const celsiusRow = newVal.find((item) => item.unit === "℃");
        const kelvinRow = newVal.find((item) => item.unit === "K");

        if (celsiusRow && kelvinRow) {
          kelvinRow.summer = celsiusRow.summer
            ? (Number(celsiusRow.summer) + 273.15).toFixed(2)
            : "";
          kelvinRow.winter = celsiusRow.winter
            ? (Number(celsiusRow.winter) + 273.15).toFixed(2)
            : "";
          kelvinRow.annual = celsiusRow.annual
            ? (Number(celsiusRow.annual) + 273.15).toFixed(2)
            : "";
        }
      },
      deep: true,
    },
  },
  methods: {
    handleExports(row) {
      window.open(this.fileUrl);
    },
    openFile(row) {
      getInfoByName(row.calcFile).then((res) => {
        if (res.data) {
          this.fileUrl = res.data.filePath;
          // 从URL中提取文件扩展名
          const extension = this.fileUrl.split(".").pop().toLowerCase();
          this.fileType = extension;
          this.lineOpen = true;
        }
      });
    },
    /* 合并单元格规则：完全还原图中效果 */
    spanMethod({ row, column, rowIndex, columnIndex }) {
      // 第一列：param 列，全部合并
      if (columnIndex === 0) {
        if (rowIndex === 0) {
          return { rowspan: this.tableData.length, colspan: 1 };
        } else {
          return { rowspan: 0, colspan: 0 }; // 其余行不显示
        }
      }

      // 第二列：titles 列，合并第2、3行（索引1和2）
      if (columnIndex === 1) {
        if (rowIndex === 1) {
          return { rowspan: 2, colspan: 1 };
        } else if (rowIndex === 2) {
          return { rowspan: 0, colspan: 0 };
        }
      }

      // 其他列默认不合并
      return { rowspan: 1, colspan: 1 };
    },
    handledownLoad() {
      // 创建隐藏的a标签并触发点击
      const link = document.createElement("a");
      link.href = "/1.xlsx";

      // 建议添加时间戳防止缓存
      link.href = link.href + "?t=" + new Date().getTime();
      link.download = "模板文件.xlsx";

      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link);
    },
    /** 导出按钮操作 */
    handleExport() {
      if (this.ids.length == 0) {
        this.$message({
          message: "请先选择文件数据",
          type: "warning",
        });
        return;
      }

      if (this.ids.length > 1) {
        this.$message({
          message: "只能进行单条导出",
          type: "warning",
        });
        return;
      }
      this.downloadget(
        `/product/taskInfo/exportWord/${this.ids[0]}`,
        `计算文件${new Date().getTime()}.docx`
      );
    },
    handleImport() {
      this.importFile = undefined;
      this.openImport = true;
    },
    cancelFormImport() {
      this.openImport = false;
    },
    submitFormImport() {
      console.log(this.importFile);
      const formData = new FormData();
      formData.append("fileUrl", this.importFile[0].url);
      taskInfoImport(formData).then((res) => {
        this.openImport = false;
        this.form = res.data;
        this.ttaskEnvList = this.form.ttaskEnvList;
        this.tableData = [
          {
            titles: "大气压力",
            param: "大气参数",
            unit: "kPa(a)",
            summer: this.ttaskEnvList[0].atmosphericPressure,
            winter: this.ttaskEnvList[1].atmosphericPressure, // 冬季平均
            annual: this.ttaskEnvList[2].atmosphericPressure, // 年平均
          },
          {
            titles: "大气温度",
            param: "大气参数",
            unit: "℃",
            summer: this.ttaskEnvList[0].ambientTemperature,
            winter: this.ttaskEnvList[1].ambientTemperature,
            annual: this.ttaskEnvList[2].ambientTemperature,
          },
          {
            titles: "大气温度",
            param: "大气参数",
            unit: "K",
            summer: this.ttaskEnvList[0].absoluteTemperature,
            winter: this.ttaskEnvList[1].absoluteTemperature,
            annual: this.ttaskEnvList[2].absoluteTemperature,
          },
          {
            titles: "绝对湿度",
            param: "大气参数",
            unit: "mb",
            summer: this.ttaskEnvList[0].absoluteHumidity,
            winter: this.ttaskEnvList[1].absoluteHumidity,
            annual: this.ttaskEnvList[2].absoluteHumidity,
          },
          {
            titles: "相对湿度",
            param: "大气参数",
            unit: "%",
            summer: this.ttaskEnvList[0].relativeHumidity,
            winter: this.ttaskEnvList[1].relativeHumidity,
            annual: this.ttaskEnvList[2].relativeHumidity,
          },
        ];
      });
    },
    closeRecords() {
      this.openRecords = false;
    },
    designSubmit(row) {
      this.rowId = row.id;
      this.openRecords = true;
    },
    handleAnnex(row) {
      this.$router.push({
        path: "/attachment/attachmentUpload",
        query: {
          projectId: row.id,
          fileType: 2,
        },
      });
    },
    closeAct() {
      this.openAct = false;
    },
    openTables(row, title) {
      this.rowId = row.id;
      this.openAct = true;
      this.ActTitle = title;
    },
    getTtaskPerformancePointList(data) {
      this.form.ttaskPerformancePointList = data;
    },
    getTtaskConditionParamList(data) {
      this.form.ttaskConditionParamList = data;
    },
    getTtaskThrustList(data) {
      this.form.ttaskThrustList = data;
    },
    getTtaskBlockLineList(data) {
      this.form.ttaskBlockLineList = data;
    },
    getTtaskEnvList(data) {
      console.log(data);
      this.form.ttaskEnvList = data;
    },
    /** 查询任务信息列表 */
    getList() {
      this.loading = true;
      listTaskInfo(this.queryParams).then((response) => {
        this.taskInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        taskNo: null,
        projectId: null,
        projectName: null,
        userName: null,
        version: null,
        drawingNo: null,
        productMedium: null,
        unitLayout: null,
        shaftConnection: null,
        bladeExecution: null,
        driverPower: null,
        calcFile: null,
        productModel: null,
        speedRpm: null,
        startupAngle: null,
        safeOperatingAngle: null,
        longTermMinOperatingAngle: null,
        maxStaticBladeAngle: null,
        startupInternalPower: null,
        frequencyRequire: null,
        curveName: null,
        adjustMode: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        delFlag: null,
        approverFlag: null,
        productModelCode: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加任务信息";
    },
    handleDetailClose() {
      // 可选：关闭后的清理工作
      this.openView = false
    },
    handleDetail(row) {
      this.detailsId = row.id;
      // this.openView = true
      this.$nextTick(() => {
        // 直接调用子组件方法
        this.$refs.approvalDetails.handleDetail();
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getTaskInfo(id).then((response) => {
        this.form = response.data;
        this.ttaskEnvList = this.form.ttaskEnvList;
        this.tableData = [
          {
            titles: "大气压力",
            param: "大气参数",
            unit: "kPa(a)",
            summer: this.ttaskEnvList[0].atmosphericPressure,
            winter: this.ttaskEnvList[1].atmosphericPressure, // 冬季平均
            annual: this.ttaskEnvList[2].atmosphericPressure, // 年平均
          },
          {
            titles: "大气温度",
            param: "大气参数",
            unit: "℃",
            summer: this.ttaskEnvList[0].ambientTemperature,
            winter: this.ttaskEnvList[1].ambientTemperature,
            annual: this.ttaskEnvList[2].ambientTemperature,
          },
          {
            titles: "大气温度",
            param: "大气参数",
            unit: "K",
            summer: this.ttaskEnvList[0].absoluteTemperature,
            winter: this.ttaskEnvList[1].absoluteTemperature,
            annual: this.ttaskEnvList[2].absoluteTemperature,
          },
          {
            titles: "绝对湿度",
            param: "大气参数",
            unit: "mb",
            summer: this.ttaskEnvList[0].absoluteHumidity,
            winter: this.ttaskEnvList[1].absoluteHumidity,
            annual: this.ttaskEnvList[2].absoluteHumidity,
          },
          {
            titles: "相对湿度",
            param: "大气参数",
            unit: "%",
            summer: this.ttaskEnvList[0].relativeHumidity,
            winter: this.ttaskEnvList[1].relativeHumidity,
            annual: this.ttaskEnvList[2].relativeHumidity,
          },
        ];
        this.open = true;
        this.title = "修改任务信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      let newdata = [
        {
          envName: "夏季平均",
          atmosphericPressure: this.tableData[0].summer,
          ambientTemperature: this.tableData[1].summer,
          absoluteTemperature: this.tableData[2].summer,
          absoluteHumidity: this.tableData[3].summer,
          relativeHumidity: this.tableData[4].summer,
        },
        {
          envName: "冬季平均",
          atmosphericPressure: this.tableData[0].winter,
          ambientTemperature: this.tableData[1].winter,
          absoluteTemperature: this.tableData[2].winter,
          absoluteHumidity: this.tableData[3].winter,
          relativeHumidity: this.tableData[4].winter,
        },
        {
          envName: "年平均",
          atmosphericPressure: this.tableData[0].annual,
          ambientTemperature: this.tableData[1].annual,
          absoluteTemperature: this.tableData[2].annual,
          absoluteHumidity: this.tableData[3].annual,
          relativeHumidity: this.tableData[4].annual,
        },
      ];
      this.form.ttaskEnvList = newdata;
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateTaskInfo(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTaskInfo(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    handleSubmit(row) {
      this.$modal
        .confirm("是否确认提交此任务信息数据项？")
        .then(function () {
          return taskSubmit({
            id: row.id,
            approverFlag: 1,
          });
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("提交成功");
        })
        .catch(() => { });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm("是否确认删除任务信息数据项？")
        .then(function () {
          return delTaskInfo(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },

    /** 导出按钮操作 */
    // handleExport() {
    //   this.download(
    //     "product/taskInfo/export",
    //     {
    //       ...this.queryParams,
    //     },
    //     `taskInfo_${new Date().getTime()}.xlsx`
    //   );
    // },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .addData {
  .el-input {
    width: 280px !important;
  }

  .el-input-number .el-input {
    width: 120px !important;
  }
}

.titles {
  margin: 15px 0;
  border-left: 3px solid #0275cd;
  padding-left: 10px;
  font-size: 16px;
  font-weight: bold;
}
</style>
